from question_classifier import *
from question_parser import *
from answer_search import *

'''问答类'''
class ChatBotGraph:
    def __init__(self):
        self.classifier = QuestionClassifier()
        self.parser = QuestionPaser()
        self.searcher = AnswerSearcher()
    

    def chat_main(self, sent):
        global res_classify_1
        # print(res_classify_1)
        answer = '抱歉，您所查询的问题我暂时无法回答，如有需要，请转至人工服务。'
        res_classify = self.classifier.classify(sent)
        if res_classify == {}:
            sent = sent + str(res_classify_1)
            res_classify = self.classifier.classify(sent)
        if not res_classify:
            return answer+'classify'
        res_sql = self.parser.parser_main(res_classify)
        final_answers = self.searcher.search_main(res_sql)
        if not final_answers:
            return answer+'parser_main'
        else:
            return '\n'.join(final_answers)

if __name__ == '__main__':
    handler = ChatBotGraph()
    while 1:
        question = input('用户:') #后续读取用户名 把用户改成用户的名称
        if handler.classifier.check_medical_1(question):
            res_classify_1 = handler.classifier.check_medical_1(question)
        answer = handler.chat_main(question)
        print('小胡:', answer)
    